<!DOCTYPE html>
<html xmlns:th="http://www.thymeleaf.org"
      xmlns:shiro="http://www.pollix.at/thymeleaf/shiro">
<head th:include="include :: header"></head>
<style>
    #bootstrap-table .fixed-table-container tbody .selected td {
        background-color: #084392 !important;
    }
</style>
<body class="hold-transition skin-blue sidebar-mini" onmousedown="xyh.disableRight()" oncontextmenu= "xyh.disableRight()">
<!--更换责任人模态框-->
<div class="modal fade" id="modal-change">
    <div class="modal-dialog" style="width:350px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">更换创建人</h4>
            </div>
            <form id="edit-parameter-form" class="form-horizontal">
                <div class="modal-header">
                    <div class="col-md-12 row" style="font-weight: bold">
                        <div class="form-inline">
                            <div class="form-group">
                                <label class="control-label">
                                    原创建人：
                                </label>
                                <label class="control-label">
                                    <span id="currentFounder">

                                    </span>
                                </label>
                            </div>
                        </div>
                        <div class="form-inline">
                            <div class="form-group">
                                <label class="control-label">
                                    新创建人：
                                </label>
                                <label class="control-label">
                                    <input id="batId" type="hide" style="display:none"/>
                                    <select id="newFounder" class="form-control">

                                    </select>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-info file-contract btn-file"
                            id="btn-save-change-founder">保存
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
</div>

<!--密码确认模态框-->
<div class="modal fade" id="modal-pass">
    <div class="modal-dialog" style="width:350px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">请输入密码验证是本人操作</h4>
            </div>
            <form id="pass-form" class="form-horizontal">
                <div class="modal-header">
                    <div class="col-md-12 row" style="font-weight: bold">
                        <div class="form-inline">
                            <div class="form-group">
                                <label class="control-label">
                                    密码：
                                </label>
                                <label class="control-label">
                                    <input name="password" type="password"/>
                                </label>
                            </div>
                        </div>
                    </div>
                </div>
                <div class="modal-footer">
                    <button type="button" class="btn btn-info file-contract btn-file"
                            id="btn-verification" data="">验证
                    </button>
                    <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
                </div>
            </form>
        </div>
    </div>
</div>
<!--创建概算模态框模态框-->
<div class="modal fade" id="modal-create">
    <div class="modal-dialog" style="width:1250px">
        <div class="modal-content">
            <div class="modal-header">
                <button type="button" class="close" data-dismiss="modal" aria-label="Close">
                    <span aria-hidden="true">&times;</span></button>
                <h4 class="modal-title">选择并创建概算</h4>
            </div>
            <div class="modal-content">
                <form class="form-horizontal">
                    <div class="col-md-12">
                        <div class="col-md-12" style="font-weight: bold">
                            <div class="form-group">
                                <label class="control-label" style="text-align: right;">
                                    样机信息如下：
                                </label>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        项目编号：
                                    </label>
                                    <label class="control-label">
                                        <span id="projectCode"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        项目名称：
                                    </label>
                                    <label class="control-label">
                                        <span id="projectName"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        厂家信息：
                                    </label>
                                    <label class="control-label">
                                        <span id="projectDemander"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        项目数量：
                                    </label>
                                    <label class="control-label">
                                        <span id="projectNum"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        年份：
                                    </label>
                                    <label class="control-label">
                                        <span id="projectCreateTime"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        成本（单台/套）：
                                    </label>
                                    <label class="control-label">
                                        <span id="orderAmount"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        合同编号：
                                    </label>
                                    <label class="control-label">
                                        <span id="contractSellCode"></span>
                                    </label>
                                </div>
                            </div>
                        </div>
                    </div>
                </form>
                <form id="modal-confirm-form" class="form-horizontal">
                    <div class="col-md-12" style="margin-top: 50px;">
                        <div class="col-md-12" style="font-weight: bold">
                            <div class="form-group">
                                <label class="control-label">
                                    概算信息如下：
                                </label>
                            </div>
                        </div>
                        <div class="col-md-12">
                            <div class="form-inline">
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        项目编号：
                                    </label>
                                    <label class="control-label">
                                        <span th:text="${project.code}"></span>
                                        <input type="hidden" name="referenceProCode" style="display: none"/>
                                        <input type="hidden" name="proCode" th:value="${project.code}" style="display: none"/>
                                        <input type="hidden" name="referenceProManufactor" style="display: none"/>
                                        <input type="hidden" name="referenceProYear" style="display: none"/>
                                        <input type="hidden" name="taskId" th:value="${taskId}" style="display: none"/>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        项目名称：
                                    </label>
                                    <label class="control-label">
                                        <span th:text="${project.name}"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        项目数量：
                                    </label>
                                    <label class="control-label">
                                        <span th:text="${project.num}"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;">
                                        需方：
                                    </label>
                                    <label class="control-label">
                                        <span th:text="${project.demander}"></span>
                                    </label>
                                </div>
                                <div class="form-group" style="margin-right:20px">
                                    <label class="control-label" style="text-align: right;"
                                           for="createForm-title">
                                        概算备注：
                                    </label>
                                    <label class="control-label">
                                        <input type="text" id="createForm-title" name="title" class="form-control"
                                               maxlength="255"/>
                                    </label>
                                    <input name="batId" type="hidden" style="display: none">
                                </div>

                            </div>
                        </div>
                    </div>
                </form>
            </div>
            <div class="modal-footer">
                <button type="button" class="btn btn-primary file-contract btn-file"
                        id="btn-confirm">确认
                </button>
                <button type="button" class="btn btn-default" data-dismiss="modal">取消</button>
            </div>
            </form>
        </div>
    </div>
</div>
<section class="content-header">
    <h1>创建概算</h1>
</section>
<section class="content">
    <div class="row">
        <div class="col-xs-12">
            <div class="box">
                <div class="box-header">
                    <form id="queryForm" class="form-horizontal">
                        <div class="row">
                            <div class="form-inline">
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        项目编号：
                                    </label>
                                    <label class="control-label">
                                        <input name="code" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目编号"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        项目名称：
                                    </label>
                                    <label class="control-label">
                                        <input name="name" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入项目名称"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        需方：
                                    </label>
                                    <label class="control-label">
                                        <input name="demander" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入需方"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        安装地点：
                                    </label>
                                    <label class="control-label">
                                        <input name="address" class="form-control" type="text" maxlength="255"
                                               placeholder="请输入安装地点"/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        设计类别：
                                    </label>
                                    <label class="control-label">
                                        <select class="form-control" name="projectClassify">
                                            <option value="">请选择</option>
                                            <option value="1">设计</option>
                                            <option value="2">非设计</option>
                                        </select>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">
                                        工作组：
                                    </label>
                                    <label class="control-label">
                                        <select class="form-control selectpicker" name="groupNameStr"
                                                data-actions-box="true" multiple onchange="changeGroupNameStrVal(this)">
                                            <option selected="selected" style="width: 200px;text-align: center"
                                                    th:each="item:${groupModelList}" th:value="${item.id}"
                                                    th:text="${item.groupName}"></option>
                                        </select>
                                        <input name="groupNameStr" type="hide" style="display: none" value=""/>
                                    </label>
                                </div>
                                <div class="form-group margin-bottom-none" style="margin-right: 25px;">
                                    <label class="control-label">任务结束时间：</label>
                                    <label class="control-label">
                                        <input type="text" class="form-control datepicker" name="startTime"
                                               readonly="readonly"/>
                                        <span> 至 </span>
                                        <input type="text" class="form-control datepicker" name="endTime"
                                               readonly="readonly"/></label>
                                </div>
                                <button id="btn-search" type="button" class="btn btn-success pull-right">
                                    搜索
                                </button>
                            </div>
                        </div>

                    </form>
                </div>
                <div id="toolbar" class="row">
                    <!--                    <button id="btn_getData" class="btn btn-success">获取数据</button>-->
                </div>
                <div class="box-body">
                    <table id="bootstrap-table"></table>
                </div>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="form-inline" id="est-title" style="display:none">
            <div class="form-group pull-left">
                <h3>
                    样机信息如下：
                </h3>
            </div>
            <div class="form-group pull-right">
                <button id="btn-hide-est" class="btn btn-default">收起</button>
            </div>
            <div class="form-group pull-right">
                <button id="btn-create-est" class="btn btn-success">选择并创建概算</button>
            </div>
        </div>
    </div>
    <div class="row">
        <div class="col-xs-1" id="box0">
        </div>
        <div class="col-xs-10" id="printDiv" style="background: white;border-color: white;box-shadow: 0 0px 0px #ccc;">
            <div class="box" style="border:0;background: white;border-color: white;box-shadow: 0 0px 0px #ccc;">
                <div id="all" class="box-body">
                </div>
            </div>
        </div>
        <div class="col-xs-1" id="box2">
            <div class="box" style="border:0;background: white;border-color: white;box-shadow: 0 0px 0px #ccc;">
                <div id="all2" class="box-body" style="width:51px;">
                </div>
            </div>
        </div>
    </div>
</section>
<div th:include="include :: footer"></div>
<script th:inline="javascript">
    let table, proCode, taskId;
    $(function () {
        /** 验证 */
        js.validate.init("modal-confirm-form", {
            fields: {
                title: {
                    validators: {
                        threshold: 1, //有1字符以上才发送ajax请求，（input中输入一个字符，插件会向服务器发送一次，设置限制，1字符以上才开始）
                        notEmpty: {message: '请输入概算名称!'},
                        callback: {
                            message: "该项目下的概算备注已存在，请重新修改!",
                            callback: function (value, validator) {
                                var flag = false;
                                $.ajax({
                                    url: ctx + 'estimateManage/titleExist', // 请求路径
                                    type: 'POST',
                                    async: false,	// 同步请求，必须是false
                                    data: {
                                        title: value, // 请求参数
                                        proCode: $("#modal-confirm-form [name='proCode']").val()
                                    },
                                    success: function (res) {
                                        flag = $.parseJSON(res).valid;
                                        if (flag == false) {
                                            $("#modal-confirm-form [name='title']").focus();
                                        }
                                    }
                                });
                                return flag;
                            }
                        }
                    }
                }
            }
        });
        /**
         * 加载列表
         */
        table = js.table.init({
            url: ctx + "estimateManage/switchList",
            paginationVAlign: 'top',                           // 指示如何垂直对齐分页。'top', 'bottom', 'both'
            showColumns: true,
            showExport: true,
            singleSelect: true, // 设置为true将禁止多选
            clickToSelect: true, // 是否启用点击选中行
            pageSize: 4,                                       // 每页的记录行数
            pageList: [4, , 10, 15, 25, 50, 100, 300, 10000],               // 可供选择的每页的行数
            onClickRow: function (row, $element) {
                $('.bg-blue').removeClass('bg-blue');
                $($element).addClass('bg-blue');
                view(row.batId, row.code + '');
            },
            columns: [
                {
                    title: '序号', field: 'id', width: '60',
                    formatter: function (value, row, index, field) {
                        var pageSize = table.bootstrapTable('getOptions').pageSize;
                        var pageNumber = table.bootstrapTable('getOptions').pageNumber;
                        return pageSize * (pageNumber - 1) + index + 1;
                    }
                },
                {
                    title: '项目编号', field: 'code',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '项目名称', field: 'name',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '需方', field: 'demander',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '安装地点', field: 'address',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '项目数量', field: 'num',
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                },
                {
                    title: '设计类别', field: 'projectClassify',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return "设计";
                        } else if (value === 2) {
                            return "非设计";
                        }
                    }
                },
                {
                    title: '成本金额（元）', field: "amount",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }, {
                    title: '创建者', field: "userName",
                    formatter: function (value, row, index) {
                        if (value != null) {
                            return value;
                        } else {
                            return '--';
                        }
                    }
                }, {
                    title: '完结时间', field: "endDate",
                    formatter: function (value, row, index) {
                        return value;
                    }
                },
                {
                    title: '数据状态', field: 'dataStatus',
                    formatter: function (value, row, index) {
                        if (value === 1) {
                            return '<lable class="badge label-success">有数据</lable>';
                        } else {
                            return '<lable class="badge label-default">无数据</lable>';
                        }
                    }
                },
                {
                    title: '操作',
                    formatter: function (value, row, index) {
                        let elements = new Array();
                        if (hasP('rou:adjust:view')) {
                            if (row.batId != null) {
                                elements.push('<button class="btn btn-info btn-xs" onclick="view(' + row.batId + ',\'' + row.code + '\')">查看样机信息</button>');
                            } else {
                                elements.push('<label class="badge label-danger">无清单数据</label>');
                            }
                        }
                        return elements.join('');
                    }
                }

            ]
        });
        /**
         * 表格搜索
         */
        $("#btn-search").click(function () {
            js.table.search(table);
        });
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-edit", function () {
            js.validate.reset("halfAdjEditForm");
            js.reset("halfAdjEditForm");
        });
        /**
         * 模态框隐藏事件， 重置表单，重置验证
         */
        js.modal.hideEvent("modal-create", function () {
            js.validate.reset("modal-confirm-form");
            $("#createForm-title").val(undefined);
            $("#createForm-remark").val(undefined);
            $("#createForm-referenceProContractPrice").val(undefined);
        });
        /**
         * 收起按钮
         */
        $("#btn-hide-est").on('click', function (e) {
            $("#est-title").hide();
            $("#all").empty();
            $("#all2").empty();
            if ($("#noteRow") != undefined) {
                $("#noteRow").remove();
            }
        });
        /**
         * 显示创建概算模态框
         */
        $("#btn-create-est").on('click', function (e) {
            js.post({
                url: ctx + 'estimateManage/checkCurrentDept',
                type: 'post',
                traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                dataType: 'json',
                contentType: "application/x-www-form-urlencoded",
                data: {
                    proCode: $("#modal-confirm-form [name='proCode']").val()
                },
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.open('modal-create');
                    }else{
                        js.modal.warning(result.msg);
                    }
                },
                error: function () {
                    js.modal.fail();
                }
            })

        });
        /**
         * 创建概算
         */
        $("#btn-confirm").on('click', function (e) {
            js.validSubmit({
                formId: "modal-confirm-form",
                url: ctx + "estimateManage/createEst",
                data: new FormData($("#modal-confirm-form")[0]),
                success: function (result) {
                    if (result.type === web_status.SUCCESS) {
                        js.modal.hide('modal-create');
                        location.href=ctx+"estimateManage/editEstCostSheet/"+result.data.id;
                    } else {
                        s.modal.warning(result.msg);
                    }
                    js.modal.closeLoading();
                },
                error: function () {
                    s.modal.warning(result.msg);
                    js.modal.closeLoading();
                }
            });
        });
    });

    /**
     * 工作组下拉框改变时修改搜索使用隐藏域的值
     * @param obj
     */
    function changeGroupNameStrVal(obj) {
        $("#queryForm [name='groupNameStr']").val($(obj).val());
    }
    /**
     * 重新加载列表
     */
    function reloadTable() {
        js.table.refresh(table);
    }

    /**
     * 查看样机信息 核算成本清单
     * @param batId
     */
    function view(batId, proCode) {
        if (batId != null) {
            $("#est-title").show();
            loadCostSheet(batId);
            loadPrototypeInfo(proCode);
        } else {
            $("#est-title").hide();
            $("#all").empty();
            $("#all2").empty();
            if ($("#noteRow") != undefined) {
                $("#noteRow").remove();
            }
        }
    }

    /**
     * 加载成本清单
     * @param mode 模式：1是全部，
     */
    function loadCostSheet(batId) {
        js.post({
            url: ctx + 'accountingInfo/loadCostSheet',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: batId
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    if (result.data.length > 0) {
                        let list = result.data;
                        $("#all").empty();
                        $("#all").html('<table id="costSheet" cellpadding="1" cellspacing="1" border="1" bgcolor="#ffffff" style="background: #FFFFFF; font-size:14px; color: #000000; text-align: center; width: 100%;font-family: \'微软雅黑\'"></table>');
                        $("#costSheet").append(' <tr><th style="width: 100px;padding: 4px;text-align: center;height: 50px;">序号</th><th style="width: 140px;padding: 4px;text-align: center;">名称</th><th style="width: 160px;text-align: center;">材质</th><th style="width:50px;text-align: center">单位</th><th style="width: 80px;text-align: center">数量</th><th style="width: 130px;text-align: center">单价<span id="priceUnit"></span></th><th style="width: 160px;text-align: center">总价<span id="totalPriceUnit"></span></th><th style="text-align: center">备注</th></tr>');
                        $("#all2").empty();
                        $("#all2").html('<table id="costSheet2" cellpadding="1" cellspacing="1" border="0" bgcolor="#ffffff" style="background: #FFFFFF; font-size:14px; color: #000000; text-align: center; width: 50px;font-family: \'微软雅黑\';border:none;"></table>');
                        $("#costSheet2").append(' <tr><th style="width: 50px;padding: 4px;text-align: center;height: 50px;border:none;"></th></tr>');

                        let tableContent = new Array();
                        let tableContent2 = new Array();
                        let partStyle;
                        let partStyle2 = " style='height: 45px;border:none;'";
                        let dataSource;
                        let remark;
                        let diyRemark;
                        let status;
                        let viewInfoFlag;
                        let remarkEditFlag;
                        let rankTopOrderNo = 0;
                        let rankSecondOrderNo = 0;
                        let rankThirdOrderNo = 0;
                        let rankFourthOrderNo = 0;
                        let rankFifthOrderNo = 0;
                        list.forEach(function (item, index, arr) {
                            if (item.displayTotalPrice === null || item.displayTotalPrice === '' || parseFloat(item.displayTotalPrice) === 0) {
                                return false;
                            }
                            let space = '';
                            if (item.isPart === 1) {
                                partStyle = ' style="background-color:white;text-align: center;padding: 4px;text-align: center;height: 45px;"';
                            } else {
                                partStyle = ' style="background-color:white;text-align: center;padding: 4px;text-align: center;height: 45px;"';
                            }
                            if (item.isInvalid === 1) {
                                remark = '作废';
                            } else if (item.remark != null) {
                                remark = item.remark + '  ';
                            } else if (item.remark === null) {
                                remark = '';
                            }
                            if (item.diyRemark != null) {
                                diyRemark = item.diyRemark;
                            } else {
                                diyRemark = '';
                            }
                            let editShowOrderNo = item.editShowOrderNo;
                            if (item.editShowOrderNo === null) {
                                editShowOrderNo = '';
                            } else if (item.rank === 1) {
                                rankTopOrderNo++;
                                editShowOrderNo = xyh.toChinesNumFun(rankTopOrderNo);
                                rankSecondOrderNo = 0;
                                rankThirdOrderNo = 0;
                            } else if (item.rank === 2) {
                                rankSecondOrderNo++;
                                editShowOrderNo = "（" + xyh.toChinesNumFun(rankSecondOrderNo) + "）";
                                rankThirdOrderNo = 0;
                            } else if (item.rank === 3) {
                                rankThirdOrderNo++;
                                editShowOrderNo = rankThirdOrderNo;
                                rankFourthOrderNo = 0;
                            } else if (item.rank === 4) {
                                rankFourthOrderNo++;
                                editShowOrderNo = rankThirdOrderNo + "." + rankFourthOrderNo;
                                rankFifthOrderNo = 0;
                            } else if (item.rank === 5) {
                                rankFifthOrderNo++;
                                editShowOrderNo = rankThirdOrderNo + "." + rankFourthOrderNo + "." + rankFifthOrderNo;
                            }
                            let name = item.name;
                            if (item.name === null) {
                                name = '';
                            }
                            let texture = item.texture;
                            if (item.texture === null) {
                                texture = '';
                            }
                            let unit = item.unit;
                            if (item.unit === null) {
                                unit = '';
                            }
                            let displayNum = item.displayNum;
                            if (item.displayNum === null) {
                                displayNum = '';
                            }
                            let displayPrice = item.displayPrice;
                            if (item.displayPrice === null) {
                                displayPrice = '';
                            }
                            let displayTotalPrice = item.displayTotalPrice;
                            if (item.displayTotalPrice === null) {
                                displayTotalPrice = '';
                            }
                            let beginTag;
                            let endTag;
                            if (item.isPart === 1) {
                                beginTag = '<th';
                                endTag = '</th>';
                            } else {
                                beginTag = '<td';
                                endTag = '</td>';
                            }
                            if (item.isMajor === 1) {
                                beginTag = '<th';
                                endTag = '</th>';
                            } else {
                                beginTag = '<td';
                                endTag = '</td>';
                            }
                            let colspanHtml = '';
                            if (item.code.includes('小计') || item.code.includes('合计')) {
                                colspanHtml = ' colspan="2" ';
                            }
                            if (hasP('ver:detail:view')) {
                                if (item.viewInfoFlag === 1) {
                                    viewInfoFlag = '<button class="btn btn-info btn-xs" onclick="info(this)" data="' + item.id + '">查看</button>';
                                } else {
                                    viewInfoFlag = '';
                                }
                            }
                            if (item.code.includes('小计') || item.code.includes('合计')) {
                                tableContent.push('<tr id="dataRow_' + index + '">' +
                                    beginTag + ' name="name" ' + colspanHtml + ' ' + partStyle + '>' + name + endTag +
                                    beginTag + ' name="texture" ' + partStyle + '>' + texture + endTag +
                                    beginTag + ' name="unit" ' + partStyle + '>' + unit + endTag +
                                    beginTag + ' name="num" ' + partStyle + '>' + displayNum + endTag +
                                    beginTag + ' name="price" ' + partStyle + '>' + displayPrice + endTag +
                                    beginTag + ' name="displayTotalPrice" ' + partStyle + '>' + displayTotalPrice + endTag +
                                    beginTag + ' name="remark"  ' + partStyle + '>' + remark + diyRemark + endTag + '</tr>');
                                tableContent2.push('<tr id="dataRow2_' + index + '">' + beginTag + partStyle2 + '>' + viewInfoFlag + endTag + '</tr>');
                            } else {
                                tableContent.push('<tr id="dataRow_' + index + '">' +
                                    beginTag + ' name="editShowOrderNo" ' + partStyle + '>' + editShowOrderNo + endTag +
                                    beginTag + ' name="name" ' + partStyle + '>' + name + endTag +
                                    beginTag + ' name="texture" ' + partStyle + '>' + texture + endTag +
                                    beginTag + ' name="unit" ' + partStyle + '>' + unit + endTag +
                                    beginTag + ' name="num" ' + partStyle + '>' + displayNum + endTag +
                                    beginTag + ' name="price" ' + partStyle + '>' + displayPrice + endTag +
                                    beginTag + ' name="displayTotalPrice" ' + partStyle + '>' + displayTotalPrice + endTag +
                                    beginTag + ' name="remark"  ' + partStyle + '>' + remark + diyRemark + endTag +
                                    '</tr>');
                                tableContent2.push('<tr id="dataRow2_' + index + '">' + beginTag + partStyle2 + '>' + viewInfoFlag + endTag + '</tr>');
                            }
                        });
                        $("#costSheet").append(tableContent.join(''));
                        $("#costSheet2").append(tableContent2.join(''));
                        loadNote(batId);

                        js.post({
                            url: ctx + 'accountingInfo/loadControlDropDownMenuDisplayParameters',
                            type: 'post',
                            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
                            dataType: 'json',
                            contentType: "application/x-www-form-urlencoded",
                            data: {
                                batId: batId
                            },
                            success: function (result) {
                                if (result.type === web_status.SUCCESS) {
                                    let priceUnit = result.data;
                                    if (priceUnit === 1) {
                                        $("#priceUnit").text("（元）");
                                        $("#totalPriceUnit").text("（元）");
                                    } else if (priceUnit === 2) {
                                        $("#priceUnit").text("（万元）");
                                        $("#totalPriceUnit").text("（万元）");
                                    }
                                }
                            },
                            error: function () {
                                js.modal.fail();
                            }
                        })
                    }
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 加载注：的内容
     */
    function loadNote(batId) {
        js.post({
            url: ctx + 'accountingInfo/loadNote',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                batId: batId
            },
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    let order = result.data;
                    if ($("#noteRow") != undefined) {
                        $("#noteRow").remove();
                    }
                    $("#all").append('<div id="noteRow" class="row" style="padding-top: 10px;"><form id="noteForm" class="form-horizontal"></form></div>');
                    $("#noteForm").append('<div class="row"><div id="priceRange" class="form-inline"></div></div>');
                    $("#priceRange").append('<div class="form-group"><label class="control-label">注：</label>' +
                        '<label class="control-label">1：价格范围：</label>' +
                        '<label class="control-label"><img name="priceRangeDesignFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">设计</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeMateriaFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">材料</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeManufactureFlag" style="marg-n-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">制造</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangePackingFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">包装</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeTransportFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">运输</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeInstall" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">安装</label>&nbsp;&nbsp;' +
                        '<label class="control-label">（&nbsp;</label>' +
                        '<label class="control-label"><img name="priceRangeInstallBusinessTravelSubsidyFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">出差补助</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeInstallAccommodationFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">食宿</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeInstallBusinessTravelFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">差旅</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeInstallHoistingFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">吊装</label><label class="control-label">&nbsp;）</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeDebugFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">调试</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeSparePartsFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">备品备件</label>&nbsp;&nbsp;' +
                        '<label class="control-label"><img name="priceRangeTransportGuaranteeFlag" style="margin-top: 0px;vertical-align: middle" width="16" height="16" /></label>' +
                        '&nbsp;<label class="control-label">保运</label>' +
                        '</div>');
                    $("#noteForm").fillData(order);
                    if (order.priceRangeInstallBusinessTravelSubsidyFlag === 1 &&
                        order.priceRangeInstallAccommodationFlag === 1 &&
                        order.priceRangeInstallBusinessTravelFlag === 1 &&
                        order.priceRangeInstallHoistingFlag === 1) {
                        $("#noteForm [name='priceRangeInstall']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeInstall']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangeDesignFlag === 1) {
                        $("#noteForm [name='priceRangeDesignFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeDesignFlag']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangeMateriaFlag === 1) {
                        $("#noteForm [name='priceRangeMateriaFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeMateriaFlag']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangeManufactureFlag === 1) {
                        $("#noteForm [name='priceRangeManufactureFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeManufactureFlag']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangePackingFlag === 1) {
                        $("#noteForm [name='priceRangePackingFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangePackingFlag']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangeTransportFlag === 1) {
                        $("#noteForm [name='priceRangeTransportFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeTransportFlag']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangeInstallBusinessTravelSubsidyFlag === 1) {
                        $("#noteForm [name='priceRangeInstallBusinessTravelSubsidyFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeInstallBusinessTravelSubsidyFlag']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangeInstallAccommodationFlag === 1) {
                        $("#noteForm [name='priceRangeInstallAccommodationFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeInstallAccommodationFlag']").attr("src", '/img/x.png');
                    }
                    if (order.priceRangeInstallBusinessTravelFlag === 1) {
                        $("#noteForm [name='priceRangeInstallBusinessTravelFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeInstallBusinessTravelFlag']").attr("src", '/img/x.png');
                    }

                    if (order.priceRangeInstallHoistingFlag === 1) {
                        $("#noteForm [name='priceRangeInstallHoistingFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeInstallHoistingFlag']").attr("src", '/img/x.png');
                    }

                    if (order.priceRangeDebugFlag === 1) {
                        $("#noteForm [name='priceRangeDebugFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeDebugFlag']").attr("src", '/img/x.png');
                    }

                    if (order.priceRangeSparePartsFlag === 1) {
                        $("#noteForm [name='priceRangeSparePartsFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeSparePartsFlag']").attr("src", '/img/x.png');
                    }

                    if (order.priceRangeTransportGuaranteeFlag === 1) {
                        $("#noteForm [name='priceRangeTransportGuaranteeFlag']").attr("src", '/img/tick4.png');
                    } else {
                        $("#noteForm [name='priceRangeTransportGuaranteeFlag']").attr("src", '/img/x.png');
                    }
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 跳转到对应明细页
     * @param id
     */
    function info(obj) {
        js.post({
            url: ctx + 'accountingInfo/jumpPage',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                id: $(obj).attr("data")
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    if (hasP('ver:detail:view')) {
                        window.open(ctx + "accountingInfo/switchPage/seeEst/" + result.data + "/" + $(obj).attr("data"));
                    }
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }

    /**
     * 加载样机信息
     * @param proCode
     */
    function loadPrototypeInfo(proCode) {
        js.post({
            url: ctx + 'estimateManage/loadPrototypeInfo',
            type: 'post',
            traditional: true,            // 阻止深度序列化， 使参数可以使用数组
            dataType: 'json',
            contentType: "application/x-www-form-urlencoded",
            data: {
                proCode: proCode
            },
            async: true,                // 异步执行
            success: function (result) {
                if (result.type === web_status.SUCCESS) {
                    $("#projectCode").text(result.data.project.code);
                    $("#modal-confirm-form [name='referenceProCode']").val(result.data.project.code);
                    $("#projectName").text(result.data.project.name);
                    $("#projectNum").text(result.data.project.num);
                    $("#projectDemander").text(result.data.project.demander);
                    $("#modal-confirm-form [name='referenceProManufactor']").val(result.data.project.demander);
                    $("#projectCreateTime").text(result.data.project.createTime);
                    $("#modal-confirm-form [name='referenceProYear']").val(result.data.project.createTime);
                    if (result.data.contract != null) {
                        $("#contractSellCode").text(result.data.contract.sellCode);
                    } else {
                        $("#contractSellCode").html('<label class="badge label-danger">此样机无合同数据</label>');
                    }
                    $("#orderAmount").text(result.data.amount + '元');
                } else {
                    js.modal.warning(result.msg);
                }
            },
            error: function () {
                js.modal.fail();
            }
        })
    }
</script>
</body>
</html>